/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aritmeticacomputacional;

import java.awt.Color;

/**
 *
 * @author João Paulo
 */
public class Principal extends javax.swing.JFrame {

    /**
     * Creates new form Principal
     */
    public Principal() {
        initComponents();
        operando1.grabFocus();
        NSinalizado.setSelected(true);
        operando1.setBackground(Color.red);
        operando2.setBackground(Color.red);
        decimalOperando1.setBackground(Color.red);
        decimalOperando2.setBackground(Color.red);
        soma.setEnabled(false);
        subtracao.setEnabled(false);
        multiplicacao.setEnabled(false);
        divisao.setEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        NSinalizado = new javax.swing.JRadioButton();
        Sinalizado = new javax.swing.JRadioButton();
        PFlutuante = new javax.swing.JRadioButton();
        soma = new javax.swing.JButton();
        subtracao = new javax.swing.JButton();
        multiplicacao = new javax.swing.JButton();
        divisao = new javax.swing.JButton();
        operando1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        operando2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        decimalOperando1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        decimalOperando2 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        resultado = new javax.swing.JTextField();
        decimalResultado = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        NSinalizado.setText("Não Sinalizado");
        NSinalizado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NSinalizadoActionPerformed(evt);
            }
        });

        Sinalizado.setText("Sinalizado");
        Sinalizado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SinalizadoActionPerformed(evt);
            }
        });

        PFlutuante.setText("Ponto Flutuante");
        PFlutuante.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PFlutuanteActionPerformed(evt);
            }
        });

        soma.setText("Soma");
        soma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                somaActionPerformed(evt);
            }
        });

        subtracao.setText("Subtração");
        subtracao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                subtracaoActionPerformed(evt);
            }
        });

        multiplicacao.setText("Multiplicação");
        multiplicacao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                multiplicacaoActionPerformed(evt);
            }
        });

        divisao.setText("Divisão");
        divisao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                divisaoActionPerformed(evt);
            }
        });

        operando1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                operando1KeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                operando1KeyTyped(evt);
            }
        });

        jLabel1.setText("Operando 1:");

        jLabel2.setText("Operando 2:");

        operando2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                operando2KeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                operando2KeyTyped(evt);
            }
        });

        jLabel3.setText("Decimal (OP1):");

        decimalOperando1.setEditable(false);

        jLabel4.setText("Decimal (OP2):");

        decimalOperando2.setEditable(false);

        jLabel5.setText("Resultado:");

        jLabel6.setText("Decimal (Resultado):");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(divisao)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(subtracao)
                            .addComponent(soma)
                            .addComponent(multiplicacao))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(NSinalizado)
                            .addComponent(Sinalizado)
                            .addComponent(PFlutuante))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel5)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(resultado, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(operando1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(decimalOperando1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(operando2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(decimalOperando2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(decimalResultado, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {divisao, multiplicacao, soma, subtracao});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {NSinalizado, PFlutuante, Sinalizado});

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {decimalOperando1, decimalOperando2, decimalResultado, jLabel1, jLabel2, jLabel3, jLabel4, jLabel5, jLabel6, operando1, operando2, resultado});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(soma)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(subtracao)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(multiplicacao))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(21, 21, 21)
                                        .addComponent(Sinalizado)
                                        .addGap(0, 0, 0)
                                        .addComponent(PFlutuante))
                                    .addComponent(NSinalizado))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(divisao))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(26, 26, 26)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(operando1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(operando2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addComponent(jLabel1))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addGap(26, 26, 26)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(decimalOperando2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(decimalOperando1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jLabel3))
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(resultado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(decimalResultado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {divisao, multiplicacao, soma, subtracao});

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {NSinalizado, PFlutuante, Sinalizado});

        layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {decimalOperando1, decimalOperando2, decimalResultado, jLabel1, jLabel2, jLabel3, jLabel4, jLabel5, jLabel6, operando1, operando2, resultado});

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void operando1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_operando1KeyTyped
        if ((evt.getKeyChar() != '0' && evt.getKeyChar() != '1') || operando1.getText().length() > 15) {
            evt.consume();
        }
    }//GEN-LAST:event_operando1KeyTyped

    private void operando1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_operando1KeyReleased
        if (operando1.getText().length() < 16) {
            operando1.setBackground(Color.red);
            decimalOperando1.setBackground(Color.red);
            soma.setEnabled(false);
            subtracao.setEnabled(false);
            multiplicacao.setEnabled(false);
            divisao.setEnabled(false);
        } else if (NSinalizado.isSelected()) {
            operando1.setBackground(Color.green);
            PontoFixoNSinalizado pf = new PontoFixoNSinalizado(new StringBuilder(operando1.getText()));
            decimalOperando1.setText(pf.getDecValue() + "");
            decimalOperando1.setBackground(Color.green);
            if (operando2.getText().length() == 16) {
                soma.setEnabled(true);
                subtracao.setEnabled(true);
                multiplicacao.setEnabled(true);
                divisao.setEnabled(true);
            }
        } else if (Sinalizado.isSelected()) {
            operando1.setBackground(Color.green);
            PontoFixoSinalizado pf = new PontoFixoSinalizado(new StringBuilder(operando1.getText()));
            decimalOperando1.setText(pf.getDecValue() + "");
            decimalOperando1.setBackground(Color.green);
            if (operando2.getText().length() == 16) {
                soma.setEnabled(true);
                subtracao.setEnabled(true);
                multiplicacao.setEnabled(true);
                divisao.setEnabled(true);
            }
        } else {
            operando1.setBackground(Color.green);
            PontoFlutuante pf = new PontoFlutuante(new StringBuilder(operando1.getText()));
            decimalOperando1.setText(pf.getDecValue() + "");
            decimalOperando1.setBackground(Color.green);
            if (operando2.getText().length() == 16) {
                soma.setEnabled(true);
            }
        }
    }//GEN-LAST:event_operando1KeyReleased

    private void NSinalizadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NSinalizadoActionPerformed
        NSinalizado.setSelected(true);
        Sinalizado.setSelected(false);
        PFlutuante.setSelected(false);
        subtracao.setEnabled(true);
        multiplicacao.setEnabled(true);
        divisao.setEnabled(true);
        decimalOperando1.setText("");
        decimalOperando2.setText("");
        if (operando1.getText().length() == 16) {
            PontoFixoNSinalizado pf = new PontoFixoNSinalizado(new StringBuilder(operando1.getText()));
            decimalOperando1.setText(pf.getDecValue() + "");
        }
        if (operando2.getText().length() == 16) {
            PontoFixoNSinalizado pf = new PontoFixoNSinalizado(new StringBuilder(operando2.getText()));
            decimalOperando2.setText(pf.getDecValue() + "");
        }
        resultado.setText("");
        resultado.setBackground(Color.WHITE);
        decimalResultado.setText("");
        decimalResultado.setBackground(Color.WHITE);

    }//GEN-LAST:event_NSinalizadoActionPerformed

    private void SinalizadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SinalizadoActionPerformed
        Sinalizado.setSelected(true);
        NSinalizado.setSelected(false);
        PFlutuante.setSelected(false);
        subtracao.setEnabled(true);
        multiplicacao.setEnabled(true);
        divisao.setEnabled(true);
        decimalOperando1.setText("");
        decimalOperando2.setText("");
        if (operando1.getText().length() == 16) {
            PontoFixoSinalizado pf = new PontoFixoSinalizado(new StringBuilder(operando1.getText()));
            decimalOperando1.setText(pf.getDecValue() + "");
        }
        if (operando2.getText().length() == 16) {
            PontoFixoSinalizado pf = new PontoFixoSinalizado(new StringBuilder(operando2.getText()));
            decimalOperando2.setText(pf.getDecValue() + "");
        }
        resultado.setText("");
        resultado.setBackground(Color.WHITE);
        decimalResultado.setText("");
        decimalResultado.setBackground(Color.WHITE);
    }//GEN-LAST:event_SinalizadoActionPerformed

    private void PFlutuanteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PFlutuanteActionPerformed
        PFlutuante.setSelected(true);
        NSinalizado.setSelected(false);
        Sinalizado.setSelected(false);
        subtracao.setEnabled(false);
        multiplicacao.setEnabled(false);
        divisao.setEnabled(false);
        decimalOperando1.setText("");
        decimalOperando2.setText("");
        if (operando1.getText().length() == 15) {
            PontoFlutuante pf = new PontoFlutuante(new StringBuilder(operando1.getText()));
            decimalOperando1.setText(pf.getDecValue() + "");
        }
        if (operando2.getText().length() == 15) {
            PontoFlutuante pf = new PontoFlutuante(new StringBuilder(operando2.getText()));
            decimalOperando2.setText(pf.getDecValue() + "");
        }
        resultado.setText("");
        resultado.setBackground(Color.WHITE);
        decimalResultado.setText("");
        decimalResultado.setBackground(Color.WHITE);
    }//GEN-LAST:event_PFlutuanteActionPerformed

    private void operando2KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_operando2KeyReleased
        if (operando2.getText().length() < 16) {
            operando2.setBackground(Color.red);
            decimalOperando2.setBackground(Color.red);
            soma.setEnabled(false);
            subtracao.setEnabled(false);
            multiplicacao.setEnabled(false);
            divisao.setEnabled(false);
        } else if (NSinalizado.isSelected()) {
            operando2.setBackground(Color.green);
            PontoFixoNSinalizado pf = new PontoFixoNSinalizado(new StringBuilder(operando2.getText()));
            decimalOperando2.setText(pf.getDecValue() + "");
            decimalOperando2.setBackground(Color.green);
            if (operando1.getText().length() == 16) {
                soma.setEnabled(true);
                subtracao.setEnabled(true);
                multiplicacao.setEnabled(true);
                divisao.setEnabled(true);
            }
        } else if (Sinalizado.isSelected()) {
            operando2.setBackground(Color.green);
            PontoFixoSinalizado pf = new PontoFixoSinalizado(new StringBuilder(operando2.getText()));
            decimalOperando2.setText(pf.getDecValue() + "");
            decimalOperando2.setBackground(Color.green);
            if (operando1.getText().length() == 16) {
                soma.setEnabled(true);
                subtracao.setEnabled(true);
                multiplicacao.setEnabled(true);
                divisao.setEnabled(true);
            }
        } else {
            operando2.setBackground(Color.green);
            PontoFlutuante pf = new PontoFlutuante(new StringBuilder(operando2.getText()));
            decimalOperando2.setText(pf.getDecValue() + "");
            decimalOperando2.setBackground(Color.green);
            if (operando1.getText().length() == 16) {
                soma.setEnabled(true);
            }
        }
    }//GEN-LAST:event_operando2KeyReleased

    private void operando2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_operando2KeyTyped
        if ((evt.getKeyChar() != '0' && evt.getKeyChar() != '1') || operando2.getText().length() > 15) {
            evt.consume();
        }
    }//GEN-LAST:event_operando2KeyTyped

    private void somaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_somaActionPerformed
        if (NSinalizado.isSelected()) {
            PontoFixoNSinalizado pf1 = new PontoFixoNSinalizado(new StringBuilder(operando1.getText()));
            PontoFixoNSinalizado pf2 = new PontoFixoNSinalizado(new StringBuilder(operando2.getText()));
            PontoFixoNSinalizado res = Operacoes.soma(pf1, pf2);
            if (res.isOverflow()) {
                resultado.setBackground(Color.red);
                decimalResultado.setBackground(Color.red);
            } else {
                resultado.setBackground(Color.green);
                decimalResultado.setBackground(Color.green);
            }
            resultado.setText(res.getSignificando().toString());
            decimalResultado.setText(res.getDecValue() + "");
        } else if (Sinalizado.isSelected()) {
            PontoFixoSinalizado pf1 = new PontoFixoSinalizado(new StringBuilder(operando1.getText()));
            PontoFixoSinalizado pf2 = new PontoFixoSinalizado(new StringBuilder(operando2.getText()));
            PontoFixoSinalizado res = Operacoes.soma(pf1, pf2);
            if (res.isOverflow()) {
                resultado.setBackground(Color.red);
                decimalResultado.setBackground(Color.red);
            } else {
                resultado.setBackground(Color.green);
                decimalResultado.setBackground(Color.green);
            }
            resultado.setText(res.getComplementoDois().toString());
            decimalResultado.setText(res.getDecValue() + "");
        } else if (PFlutuante.isSelected()) {
            PontoFlutuante pf1 = new PontoFlutuante(new StringBuilder(operando1.getText()));
            PontoFlutuante pf2 = new PontoFlutuante(new StringBuilder(operando2.getText()));
            PontoFlutuante res = Operacoes.soma(pf1, pf1);
            decimalResultado.setText(res.getDecValue() + "");
        }
    }//GEN-LAST:event_somaActionPerformed

    private void subtracaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_subtracaoActionPerformed
        if (NSinalizado.isSelected()) {
            PontoFixoNSinalizado pf1 = new PontoFixoNSinalizado(new StringBuilder(operando1.getText()));
            PontoFixoNSinalizado pf2 = new PontoFixoNSinalizado(new StringBuilder(operando2.getText()));
            PontoFixoNSinalizado res = Operacoes.sub(pf1, pf2);
            if (res.isOverflow()) {
                resultado.setBackground(Color.red);
                decimalResultado.setBackground(Color.red);
            } else {
                resultado.setBackground(Color.green);
                decimalResultado.setBackground(Color.green);
            }
            resultado.setText(res.getSignificando().toString());
            decimalResultado.setText(res.getDecValue() + "");
        } else if (Sinalizado.isSelected()) {
            PontoFixoSinalizado pf1 = new PontoFixoSinalizado(new StringBuilder(operando1.getText()));
            PontoFixoSinalizado pf2 = new PontoFixoSinalizado(new StringBuilder(operando2.getText()));
            if (pf2.getComplementoDois().charAt(0) == '0') {
                pf2.complementoDois();
            } else {
                pf2.complementoUm();
            }
            PontoFixoSinalizado res = Operacoes.soma(pf1, pf2);
            if (res.isOverflow()) {
                resultado.setBackground(Color.red);
                decimalResultado.setBackground(Color.red);
            } else {
                resultado.setBackground(Color.green);
                decimalResultado.setBackground(Color.green);
            }
            resultado.setText(res.getComplementoDois().toString());
            decimalResultado.setText(res.getDecValue() + "");
        }
    }//GEN-LAST:event_subtracaoActionPerformed

    private void multiplicacaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multiplicacaoActionPerformed
        if (NSinalizado.isSelected()) {
            PontoFixoNSinalizado pf1 = new PontoFixoNSinalizado(new StringBuilder(operando1.getText()));
            PontoFixoNSinalizado pf2 = new PontoFixoNSinalizado(new StringBuilder(operando2.getText()));
            PontoFixoNSinalizado res = Operacoes.mult(pf1, pf2);
            if (res.isOverflow()) {
                resultado.setBackground(Color.red);
                decimalResultado.setBackground(Color.red);
            } else {
                resultado.setBackground(Color.green);
                decimalResultado.setBackground(Color.green);
            }
            resultado.setText(res.getSignificando().toString());
            decimalResultado.setText(res.getDecValue() + "");
        } else if (Sinalizado.isSelected()) {
            PontoFixoSinalizado pf1 = new PontoFixoSinalizado(new StringBuilder(operando1.getText()));
            PontoFixoSinalizado pf2 = new PontoFixoSinalizado(new StringBuilder(operando2.getText()));
            PontoFixoSinalizado res = Operacoes.mult(pf1, pf2);
            if (res.isOverflow()) {
                resultado.setBackground(Color.red);
                decimalResultado.setBackground(Color.red);
            } else {
                resultado.setBackground(Color.green);
                decimalResultado.setBackground(Color.green);
            }
            resultado.setText(res.getComplementoDois().toString());
            decimalResultado.setText(res.getDecValue() + "");
        }
    }//GEN-LAST:event_multiplicacaoActionPerformed

    private void divisaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_divisaoActionPerformed
        if (NSinalizado.isSelected()) {
            PontoFixoNSinalizado pf1 = new PontoFixoNSinalizado(new StringBuilder(operando1.getText()));
            PontoFixoNSinalizado pf2 = new PontoFixoNSinalizado(new StringBuilder(operando2.getText()));
            PontoFixoNSinalizado res = Operacoes.div(pf1, pf2);
            if (res.isOverflow()) {
                resultado.setBackground(Color.red);
                decimalResultado.setBackground(Color.red);
            } else {
                resultado.setBackground(Color.green);
                decimalResultado.setBackground(Color.green);
            }
            resultado.setText(res.getSignificando().toString());
            decimalResultado.setText(res.getDecValue() + "");
        } else if (Sinalizado.isSelected()) {
            PontoFixoSinalizado pf1 = new PontoFixoSinalizado(new StringBuilder(operando1.getText()));
            PontoFixoSinalizado pf2 = new PontoFixoSinalizado(new StringBuilder(operando2.getText()));
            PontoFixoSinalizado res = Operacoes.div(pf1, pf2);
            if (res.isOverflow()) {
                resultado.setBackground(Color.red);
                decimalResultado.setBackground(Color.red);
            } else {
                resultado.setBackground(Color.green);
                decimalResultado.setBackground(Color.green);
            }
            resultado.setText(res.getComplementoDois().toString());
            decimalResultado.setText(res.getDecValue() + "");
        }
    }//GEN-LAST:event_divisaoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton NSinalizado;
    private javax.swing.JRadioButton PFlutuante;
    private javax.swing.JRadioButton Sinalizado;
    private javax.swing.JTextField decimalOperando1;
    private javax.swing.JTextField decimalOperando2;
    private javax.swing.JTextField decimalResultado;
    private javax.swing.JButton divisao;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JButton multiplicacao;
    private javax.swing.JTextField operando1;
    private javax.swing.JTextField operando2;
    private javax.swing.JTextField resultado;
    private javax.swing.JButton soma;
    private javax.swing.JButton subtracao;
    // End of variables declaration//GEN-END:variables
}
